const url = '/api';

const Request = (options) => {
	return new Promise((resolve, reject) => {
		let token = uni.getStorageSync("token") || ''
		uni.request({
			url: url + options.url,
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				Token: token,
				lang:'en-us'
			},
			success: (res) => {
				console.log(res)
				if(res.data.code == 401){
					uni.showToast({
						title:res.data.msg,
						icon:'none'
					})
					setTimeout(()=>{
						uni.reLaunch({
							url:'/pages/login/index'
						})
					},1000)
				}
				resolve(res);
			},
			fail: (err) => {
				reject(err);
			},
		});
	})
}
export default Request